package cn.yunhe.controller;

import cn.yunhe.entity.Admin;
import cn.yunhe.entity.Stock;
import cn.yunhe.entity.Type;
import cn.yunhe.service.IStockService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/after/StockUpdateServlet")
public class StockUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取表单提交的数据
        int stockId = Integer.parseInt(request.getParameter("stockId"));//仓库编号
        String stockName = request.getParameter("stockName");//仓库名称
        int number = Integer.parseInt(request.getParameter("number"));//仓库实际存储的数量
        int maxNumber = Integer.parseInt(request.getParameter("maxNumber"));//仓库最大容量
        int typeId = Integer.parseInt(request.getParameter("typeId"));//快递类型  快递类型编号
        int state = Integer.parseInt(request.getParameter("state"));//仓库状态
        String intro = request.getParameter("intro");//仓库描述
        int adminId = Integer.parseInt(request.getParameter("adminId"));//仓库管理员 管理员编号
        //创建一个type对象
        Type type = new Type();
        type.setTypeId(typeId);
        //创建一个admin对象
         Admin admin = new Admin();
         admin.setAdminId(adminId);
         //创建一个stock对象
        Stock stock = new Stock(stockId, stockName, number, maxNumber, intro, state, type,admin);
        IStockService iStockService = new IStockService();
        //调用service的方法
        boolean flag = iStockService.stockUpdate(stock);
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        if (flag) {
            System.out.println("修改成功");
            out.print("true");
        } else {
            System.out.println("修改失败");
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
